local guanxing = fk.CreateSkill {

  name = "joy__guanxing",

  tags = {  },

}



guanxing:addEffect(fk.EventPhaseStart, {
  name = "joy__guanxing",
  anim_type = "control",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(guanxing.name) and
    (player.phase == Player.Start or (player.phase == Player.Finish and player:getMark("joy__guanxing-turn") > 0))
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local result = room:askForGuanxing(player, room:getNCards(#room.alive_players == 2 and 3 or 5))
    if #result.top == 0 and player.phase == Player.Start then
      room:setPlayerMark(player, "joy__guanxing-turn", 1)
    end
  end,
})

return guanxing